home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdeprint / kprintdialogpage.h < prev   
Encoding:
C/C++ Source or Header  |  2005-11-08  |  6.0 KB  |  191 lines

  1. /*
  2.  *  This file is part of the KDE libraries
  3.  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
  4.  *
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License version 2 as published by the Free Software Foundation.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public License
  16.  *  along with this library; see the file COPYING.LIB.  If not, write to
  17.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  *  Boston, MA 02110-1301, USA.
  19.  **/
  20.  
  21. #ifndef KPRINTDIALOGPAGE_H
  22. #define KPRINTDIALOGPAGE_H
  23.  
  24. #include <qwidget.h>
  25. #include <qmap.h>
  26.  
  27. #include <kdelibs_export.h>
  28.  
  29. class KMPrinter;
  30. class DrMain;
  31.  
  32. /**
  33.  * This class is intended to be used as base class for customized print dialog page. One of
  34.  * the feature of the KDE print framework is to allow to customize the print dialog to
  35.  * add some application specific print options. This is done by subclassing KPrintDialogPage
  36.  * and reimplementing the 3 virtual functions getOptions, setOptions and
  37.  * isValid(). The print options will be stored in the KPrinter object, and will be
  38.  * accessible via KPrinter::option(). The option name should follow the form
  39.  * "kde-appname-optionname" for internal reasons.
  40.  *
  41.  * \code
  42.  * #include <kdeprint/kprintdialogpage.h>
  43.  *
  44.  * class MyDialogPage : public KPrintDialogPage
  45.  * {
  46.  * public:
  47.  *   MyDialogPage( QWidget *parent = 0, const char *name = 0 );
  48.  *
  49.  *   //reimplement virtual functions
  50.  *   void getOptions( QMap<QString,QString>& opts, bool incldef = false );
  51.  *   void setOptions( const QMap<QString,QString>& opts );
  52.  *   bool isValid( QString& msg );
  53.  *
  54.  * private:
  55.  *   QComboBox *m_fontcombo;
  56.  * };
  57.  *
  58.  * MyDialogPage::MyDialogPage( QWidget *parent, const char *name )
  59.  * : KPrintDialogPage( parent, name )
  60.  * {
  61.  *   setTitle( i18n( "My Page" ) );
  62.  * }
  63.  *
  64.  * void MyDialogPage::getOptions( QMap<QString,QString>& opts, bool incldef )
  65.  * {
  66.  *   if ( incldef || m_fontcombo->currentText() != mydefaultvalue )
  67.  *     opts[ "kde-myapp-fontname" ] = m_fontcombo->currentText();
  68.  * }
  69.  *
  70.  * void MyDialogPage::setOptions( const QMap<QString,QString>& opts )
  71.  * {
  72.  *   QString fntname = opts[ "kde-myapp-fontname" ];
  73.  *   m_fontcombo->setEditText( fntname );
  74.  * }
  75.  *
  76.  * bool MyDialogPage::isValid( QString& msg)
  77.  * {
  78.  *   if ( m_fontcombo->currentText().isEmpty() )
  79.  *   {
  80.  *     msg = i18n( "Font name cannot be empty." );
  81.  *     return false;
  82.  *   }
  83.  *   return true;
  84.  * }
  85.  * \endcode
  86.  *
  87.  * @short Base class for customized print dialog pages.
  88.  * @see KPrinter
  89.  */
  90. class KDEPRINT_EXPORT KPrintDialogPage : public QWidget
  91. {
  92.     Q_OBJECT
  93. public:
  94.     /**
  95.      * Standard constructor.
  96.      */
  97.     KPrintDialogPage(QWidget *parent = 0, const char *name = 0);
  98.     /**
  99.      * Modified constructor. For internal use only.
  100.      */
  101.     KPrintDialogPage(KMPrinter *pr, DrMain *dr = 0, QWidget *parent = 0, const char *name = 0);
  102.     /**
  103.      * Destructor
  104.      */
  105.     virtual ~KPrintDialogPage();
  106.  
  107.     /**
  108.      * This function is called to fill the structure @p opts with the selected options from this dialog
  109.      * page. If @p incldef is true, include also options with default values, otherwise discard them.
  110.      * Reimplement this function in subclasses.
  111.      * @param opts the option set to fill
  112.      * @param incldef if true, include also options with default values
  113.      * @see setOptions()
  114.      */
  115.     virtual void getOptions(QMap<QString,QString>& opts, bool incldef = false);
  116.     /**
  117.      * This function is called to update the current page with the options contained in @p opts.
  118.      * Reimplement it in subclasses.
  119.      * @param opts the structure containing the options to update the page
  120.      */
  121.     virtual void setOptions(const QMap<QString,QString>& opts);
  122.     /**
  123.      * Returns true if options selected in the page are valid (no conflict), false otherwise.
  124.      * When returning false, @p msg should contain an error message explaining what is wrong
  125.      * in the selected options.
  126.      * @param msg should contain an error message when returning false
  127.      * @returns valid status
  128.      */
  129.     virtual bool isValid(QString& msg);
  130.     /**
  131.      * Get the ID of the page. Not used yet.
  132.      * @returns the page ID
  133.      * @see setId()
  134.      */
  135.     int id() const                 { return m_ID; }
  136.     /**
  137.      * Set the ID of the page. Not used yet.
  138.      * @param ID the ID number
  139.      * @see id()
  140.      */
  141.     void setId(int ID)            { m_ID = ID; }
  142.     /**
  143.      * Get the page title.
  144.      * @returns the page title
  145.      * @see setTitle()
  146.      */
  147.     QString    title() const             { return m_title; }
  148.     /**
  149.      * Set the page title. This title will be used as tab name for this page in the print
  150.      * dialog.
  151.      * @param txt the page title
  152.      * @see title()
  153.      */
  154.     void setTitle(const QString& txt)    { m_title = txt; }
  155.     /**
  156.      * Tell wether or not the page should be disable if a non real printer (special
  157.      * printer) is selected in the print dialog. Returns false by default. Application
  158.      * specific pages usually corresponds to printer-independent options, so the
  159.      * page should be kept enabled whatever the selected printer. The default value
  160.      * is then correct and your application doesn't to change anything.
  161.      * @returns true if the page should be disabled for non real printers
  162.      * @see setOnlyRealPrinters()
  163.      */
  164.     bool onlyRealPrinters() const    { return m_onlyreal; }
  165.     /**
  166.      * Change the page state when a non real printer is selected in the print dialog.
  167.      * Usually, the default value (false) is OK in most cases and you don't need to
  168.      * call this function explicitly.
  169.      * @param on if true, then the page will be disabled if a non real printer is selected
  170.      * @see onlyRealPrinters()
  171.      */
  172.     void setOnlyRealPrinters(bool on = true) { m_onlyreal = on; }
  173.     /**
  174.      * For internal use only.
  175.      */
  176.     DrMain* driver()             { return m_driver; }
  177.     /**
  178.      * For internal use only
  179.      */
  180.     KMPrinter* printer()            { return m_printer; }
  181.  
  182. protected:
  183.     KMPrinter    *m_printer;
  184.     DrMain        *m_driver;
  185.     int         m_ID;
  186.     QString        m_title;
  187.     bool        m_onlyreal;
  188. };
  189.  
  190. #endif
  191.